/*   1:    */ package tt.dz.web.controller.menu;
/*   2:    */ 
/*   3:    */ import com.alibaba.fastjson.JSON;
/*   4:    */ import java.util.ArrayList;
/*   5:    */ import java.util.HashMap;
/*   6:    */ import java.util.Iterator;
/*   7:    */ import java.util.List;
/*   8:    */ import java.util.Map;
/*   9:    */ import java.util.Set;
/*  10:    */ import javax.annotation.Resource;
/*  11:    */ import javax.servlet.http.HttpServletRequest;
/*  12:    */ import org.apache.shiro.SecurityUtils;
/*  13:    */ import org.apache.shiro.session.Session;
/*  14:    */ import org.apache.shiro.subject.Subject;
/*  15:    */ import org.springframework.stereotype.Controller;
/*  16:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  17:    */ import org.springframework.web.bind.annotation.ResponseBody;
/*  18:    */ import tt.dz.biz.service.menu.MenuService;
/*  19:    */ import tt.dz.common.LogUtil;
/*  20:    */ import tt.dz.vo.MenuVO;
/*  21:    */ import tt.dz.vo.ResponseModle;
/*  22:    */ import tt.dz.vo.RoleMenuVO;
/*  23:    */ import tt.dz.vo.RoleVO;
/*  24:    */ import tt.dz.web.controller.BaseController;
/*  25:    */ 
/*  26:    */ @Controller
/*  27:    */ public class MenuController
/*  28:    */   extends BaseController
/*  29:    */ {
/*  30:    */   @Resource(name="menuService")
/*  31:    */   private MenuService menuService;
/*  32:    */   
/*  33:    */   @RequestMapping(value={"/queryMenuByRole"}, produces={"application/json;charset=UTF-8"})
/*  34:    */   @ResponseBody
/*  35:    */   public String queryMenuByRole()
/*  36:    */   {
/*  37: 45 */     ResponseModle responseModle = null;
/*  38:    */     try
/*  39:    */     {
/*  40: 47 */       Subject subject = SecurityUtils.getSubject();
/*  41: 48 */       Set<String> roleSet = (Set)subject.getSession().getAttribute("dzSessionAttrRolesList");
/*  42: 49 */       String userName = (String)subject.getSession().getAttribute("dzSessionAttrUsername");
/*  43: 50 */       List<String> roleIdList = new ArrayList(roleSet);
/*  44: 51 */       List<MenuVO> menuList = this.menuService.queryMenuByRole(roleIdList);
/*  45: 52 */       MenuVO menuVO = new MenuVO();
/*  46: 53 */       menuVO.setMenuId("#");
/*  47: 54 */       recursiveMenu(menuVO, menuList);
/*  48: 55 */       removeChildren(menuList);
/*  49: 56 */       Map rs = new HashMap();
/*  50: 57 */       rs.put("userName", userName);
/*  51: 58 */       rs.put("menuList", menuList);
/*  52: 59 */       responseModle = new ResponseModle("success", rs);
/*  53:    */     }
/*  54:    */     catch (Exception e)
/*  55:    */     {
/*  56: 61 */       LogUtil.error("查询角色菜单异常", e);
/*  57: 62 */       responseModle = new ResponseModle("error", new ArrayList());
/*  58:    */     }
/*  59: 64 */     return JSON.toJSONString(responseModle);
/*  60:    */   }
/*  61:    */   
/*  62:    */   @RequestMapping(value={"/queryMenuByRoleId"}, produces={"application/json;charset=UTF-8"})
/*  63:    */   @ResponseBody
/*  64:    */   public String queryMenuByRole(HttpServletRequest rq)
/*  65:    */   {
/*  66: 74 */     ResponseModle responseModle = null;
/*  67:    */     try
/*  68:    */     {
/*  69: 76 */       String roleId = rq.getParameter("roleId");
/*  70: 77 */       RoleVO rv = new RoleVO();
/*  71: 78 */       rv.setRoleId(roleId);
/*  72: 79 */       List<MenuVO> menuList = this.menuService.queryMenuByRole(rv);
/*  73: 80 */       MenuVO menuVO = new MenuVO();
/*  74: 81 */       menuVO.setMenuId("#");
/*  75: 82 */       recursiveMenu(menuVO, menuList);
/*  76: 83 */       removeChildren(menuList);
/*  77: 84 */       Map rs = new HashMap();
/*  78: 85 */       rs.put("menuList", menuList);
/*  79: 86 */       responseModle = new ResponseModle("success", rs);
/*  80:    */     }
/*  81:    */     catch (Exception e)
/*  82:    */     {
/*  83: 88 */       LogUtil.error("查询角色菜单异常", e);
/*  84: 89 */       responseModle = new ResponseModle("error", new ArrayList());
/*  85:    */     }
/*  86: 91 */     return JSON.toJSONString(responseModle);
/*  87:    */   }
/*  88:    */   
/*  89:    */   @RequestMapping(value={"/queryAllMenu"}, produces={"application/json;charset=UTF-8"})
/*  90:    */   @ResponseBody
/*  91:    */   public String queryAllMenu(HttpServletRequest rq)
/*  92:    */   {
/*  93:101 */     ResponseModle responseModle = null;
/*  94:    */     try
/*  95:    */     {
/*  96:103 */       List<MenuVO> menuList = this.menuService.queryAllMenu();
/*  97:104 */       MenuVO menuVO = new MenuVO();
/*  98:105 */       menuVO.setMenuId("#");
/*  99:106 */       recursiveMenu(menuVO, menuList);
/* 100:107 */       removeChildren(menuList);
/* 101:108 */       Map rs = new HashMap();
/* 102:109 */       rs.put("menuList", menuList);
/* 103:110 */       responseModle = new ResponseModle("success", rs);
/* 104:    */     }
/* 105:    */     catch (Exception e)
/* 106:    */     {
/* 107:112 */       LogUtil.error("查询角色菜单异常", e);
/* 108:113 */       responseModle = new ResponseModle("error", new ArrayList());
/* 109:    */     }
/* 110:115 */     return JSON.toJSONString(responseModle);
/* 111:    */   }
/* 112:    */   
/* 113:    */   @RequestMapping(value={"/modifyRoleMenu"}, produces={"application/json;charset=UTF-8"})
/* 114:    */   @ResponseBody
/* 115:    */   public String ModifyRoleMenu(HttpServletRequest request)
/* 116:    */   {
/* 117:124 */     boolean excuteFlag = false;
/* 118:    */     try
/* 119:    */     {
/* 120:126 */       List<RoleMenuVO> roleMenuVOs = JSON.parseArray(request.getParameter("roleMenuVOs"), RoleMenuVO.class);
/* 121:    */       
/* 122:128 */       excuteFlag = this.menuService.batchModifyRoleMenu(roleMenuVOs);
/* 123:    */     }
/* 124:    */     catch (Exception e)
/* 125:    */     {
/* 126:130 */       LogUtil.error("变更角色菜单权限异常", e);
/* 127:    */     }
/* 128:132 */     return JSON.toJSONString(assemblyResponseData(excuteFlag, null));
/* 129:    */   }
/* 130:    */   
/* 131:    */   public void getChildrenMenu(MenuVO menuVO, List<MenuVO> menuList)
/* 132:    */   {
/* 133:136 */     Iterator<MenuVO> iterator = menuList.iterator();
/* 134:137 */     MenuVO sourceMenu = null;
/* 135:138 */     while (iterator.hasNext())
/* 136:    */     {
/* 137:139 */       sourceMenu = (MenuVO)iterator.next();
/* 138:140 */       if (sourceMenu.getParentMenuId().equals(menuVO.getMenuId()))
/* 139:    */       {
/* 140:141 */         sourceMenu.setParentMenuName(menuVO.getMenuName());
/* 141:142 */         menuVO.getChildrenMenu().add(sourceMenu);
/* 142:    */       }
/* 143:    */     }
/* 144:    */   }
/* 145:    */   
/* 146:    */   public void recursiveMenu(MenuVO menuVO, List<MenuVO> menuList)
/* 147:    */   {
/* 148:148 */     getChildrenMenu(menuVO, menuList);
/* 149:149 */     if (menuVO.getChildrenMenu().size() > 0)
/* 150:    */     {
/* 151:150 */       Iterator<MenuVO> iterator = menuVO.getChildrenMenu().iterator();
/* 152:151 */       MenuVO sourceMenu = null;
/* 153:152 */       while (iterator.hasNext())
/* 154:    */       {
/* 155:153 */         sourceMenu = (MenuVO)iterator.next();
/* 156:154 */         recursiveMenu(sourceMenu, menuList);
/* 157:    */       }
/* 158:    */     }
/* 159:    */   }
/* 160:    */   
/* 161:    */   public void removeChildren(List<MenuVO> menuList)
/* 162:    */   {
/* 163:160 */     Iterator<MenuVO> iterator = menuList.iterator();
/* 164:161 */     while (iterator.hasNext()) {
/* 165:162 */       if (!"#".equals(((MenuVO)iterator.next()).getParentMenuId())) {
/* 166:163 */         iterator.remove();
/* 167:    */       }
/* 168:    */     }
/* 169:    */   }
/* 170:    */ }


/* Location:           F:\work\pengyu\mainServer\WEB-INF\classes\
 * Qualified Name:     tt.dz.web.controller.menu.MenuController
 * JD-Core Version:    0.7.0.1
 */